﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BareWeb.FluentAzureDiagnostics.Tests
{
    [TestClass]
    public class AzureBlobStorageTests
    {
        [TestMethod]
        public void DocumentContainsDeploymentId_Contains_True()
        {
            var input = @"<fluent><deployments><deployment>1234567890</deployment></deployments></fluent>";

            var expected = true;

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.DocumentContainsDeploymentId(input, "1234567890");

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void DocumentContainsDeploymentId_ContainsMany_True()
        {
            var input = @"<fluent><deployments><deployment>a1234567890</deployment><deployment>b1234567890</deployment><deployment>c1234567890</deployment></deployments></fluent>";

            var expected = true;

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.DocumentContainsDeploymentId(input, "b1234567890");

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void DocumentContainsDeploymentId_NotContains_False()
        {
            var input = @"<fluent><deployments><deployment>1234567890</deployment></deployments></fluent>";

            var expected = false;

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.DocumentContainsDeploymentId(input, "50");

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void DocumentContainsDeploymentId_NotContainsMany_False()
        {
            var input = @"<fluent><deployments><deployment>a1234567890</deployment><deployment>b1234567890</deployment><deployment>c1234567890</deployment></deployments></fluent>";

            var expected = false;

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.DocumentContainsDeploymentId(input, "z1234567890");

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetXmlFluentFile_KnownId_CorrectXml()
        {
            var expected = XDocument.Parse("<fluent><deployments><deployment>a1234567890</deployment></deployments></fluent>").ToString();

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.GetXmlFluentFile("a1234567890");
            
            Assert.AreEqual(expected, actual);

        }

        [TestMethod]
        public void AddXmlFluentItem_KnownId_CorrectXml()
        {
            var startingPoint = XDocument.Parse("<fluent><deployments><deployment>a1234567890</deployment></deployments></fluent>").ToString();
            ;
            var expected = XDocument.Parse("<fluent><deployments><deployment>a1234567890</deployment><deployment>b1234567890</deployment></deployments></fluent>").ToString();

            var target = new AzureBlobStorage(null, "abc", "abc", "abc");

            var actual = target.AddXmlFluentItem(startingPoint, "b1234567890");

            Assert.AreEqual(expected, actual);

        }
    }
}
